<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <h2>这是百度一个不正常的操作，百度相关</h2>
    <script>
        let zh = "admin123zhadmin456"
        //    字符串search方法 返回字符所在位置 找不到返回-1
        console.log(zh.search('d')); // 1
        // 字符串match方法 找到匹配的字符
        console.log(zh.match(/a/g)); // ["a", "a"]

        let hd = `
            https://hcly.com
            http://www.sina.com.cn
            https://www.baidu.com
        `
        // match返回匹配结果
        let reg = /https?:\/\/(\w+\.)?(\w+\.)+(com|cn|org|cc)/gi;
        console.log(hd.match(reg)); // ["https://hcly.com", "http://www.sina.com.cn", "https://www.baidu.com"]

        let date = '2020-10-10'
        let date1 = '2020/10/10'
        // 字符串拆分split
        console.log(date.split(/[-\/]/)); // ["2020", "10", "10"]
        console.log(date1.split(/[-\/]/)); // ["2020", "10", "10"]
        console.log(date1.replace(/[-\/]/g,'@')); // 2020@10@10

        let h2 = document.querySelector('h2');
        // $& 获取匹配的内容
        h2.innerHTML = h2.innerHTML.replace(/百度/g,`<a href="http://www.baidu.com">$&</a>`);
    </script>
</body>

</html>